package com.jiantong.admin.model;

import com.jiantong.admin.dto.Butcher_AreaDto;
import com.jiantong.admin.dto.CityAreaDto;
import com.jiantong.user.model.BreedFactory;
import com.jiantong.user.model.ButcherFactory;
import com.jiantong.user.service.BreedFactoryReadService;
import com.jiantong.user.service.ButcherFactoryReadService;
import io.terminus.boot.rpc.common.annotation.RpcConsumer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ThinkPad on 2017/7/20.
 */

public class Common {

    private BreedFactoryReadService breedFactoryReadService;

    private ButcherFactoryReadService butcherFactoryReadService;

    public Common(BreedFactoryReadService breedFactoryReadService, ButcherFactoryReadService butcherFactoryReadService) {
        this.breedFactoryReadService = breedFactoryReadService;
        this.butcherFactoryReadService = butcherFactoryReadService;
    }

    /**
     * 查询所有市下面的区
     * @return CityAreaDto
     */

    public List<CityAreaDto> serachCityAreaDtoInBreefctory(){
        List<CityAreaDto> cityAreaDtoArrayList=new ArrayList<>();
        List <String>list= breedFactoryReadService.serachAllCity();

        for (String city :list){
            CityAreaDto cityAreaDto=new CityAreaDto();
            cityAreaDto.setCity(city);
            List<String> regions=  breedFactoryReadService.serachAllregion(city);

            cityAreaDto.setRegions(regions);
            cityAreaDtoArrayList.add(cityAreaDto);
        }

        return cityAreaDtoArrayList;
    }
    //查询所有养殖场
    public List<BreedFactory> findAllBreedFactory(){

        return breedFactoryReadService.pagingBreedRecord(1,1000000,null).getResult().getData();
    }
    //查询所有屠宰场
    public List<ButcherFactory> findAllButcher(){
        return butcherFactoryReadService.findAllButcherFactory().getResult().getData();
    }

    public List<Butcher_AreaDto> findCity_region(){
        List<String> cityList = butcherFactoryReadService.findAllCity().getResult();
        List<Butcher_AreaDto> butcherAreaList = new ArrayList<>();
        for (String city:cityList) {
            List<String> regionList = butcherFactoryReadService.findRegionByCity(city).getResult();
            butcherAreaList.add(new Butcher_AreaDto(city,regionList));
        }
        return butcherAreaList;
    }

}
